package UCM;

import Source.CreateFlight;
import Views.ViewCreateFlight;

/**
 *
 * @author Joshua King
 */
public class UCCreateFlight implements UCController {
    private ViewCreateFlight view;
    private CreateFlight model = new CreateFlight();

    public UCCreateFlight(ViewCreateFlight aView) {
        this.view = aView;
        view.loadTo(model);
    }

    /**
Precondition: The manager is logged in, tis view some create flight page.

   1. Manager enters details than clicks create flight.
   2. System loads data to the model.
   3. System confirm the validity of the information.
   4. System commits data.
   5. System refreshes the create flight UI indicating success. 

Postcondition: The manager is on the create flight UI and a new flight has been created.

Unsuccessful Outcome:

    * 3a) The details entered by the manager are inappropriate.
         1. System refreshes the UI and explains errors to the manager. 
    * 4a) System can't commit data.
         1. System updates the UI informing the manager that the service is currently unavailable. 
    * 4b) System receives notice that an error has occurred.
         1. System updates the UI informing the manager that there was an internal error. 
     */
    public void run() {
        //2. System loads data to the model.
        view.loadData();
        //3. System confirm the validity of the information.
        if (model.checkValidity()) {
            //4. System commits data.
            if (model.commitData()) {
                //5. System refreshes the create flight UI indicating success.
                view.updateSuccess();
            } else {
               // * 4a) System can't commit data.
               // 1. System updates the UI informing the manager that the service is currently unavailable. 
               // * 4b) System receives notice that an error has occurred.
               // 1. System updates the UI informing the manager that there was an internal error.
                view.updateFailure();
            }
        } else {
            //* 3a) The details entered by the manager are inappropriate.
            //1. System refreshes the UI and explains errors to the manager. 
            view.updateFailure();
        }
        
    }

}
